{% extends 'web/layout/manage.html' %}
{% load static %}
{% block title %}Project Show{% endblock title %}
{% block css %}
    <style>
        img {
            width: 100%;
        }
        .project{
            margin-top:10px;
            margin-bottom:10px;
        }
         .panel-body {
            padding: 0;
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: flex-start;
            flex-wrap: wrap;
        }

        .panel-body > .item {
            border-radius: 6px;
            width: 128px;
            border: 1px solid #dddddd;
            margin: 20px 10px;

        }

        .panel-body > .item:hover {
            border: 1px solid #f0ad4e;
        }

        .panel-body > .item > .title {
            height: 54px;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 15px;
            text-decoration: none;
        }

        .panel-body > .item > .info {
            padding: 10px 10px;

            display: flex;
            justify-content: space-between;

            border-bottom-left-radius: 6px;
            border-bottom-right-radius: 6px;
            color: #8c8c8c;

        }

        .panel-body > .item > .info a {
            text-decoration: none;
        }

        .panel-body > .item > .info .fa-star {
            font-size: 18px;
        }

        .color-radio label {
            margin-left: 0;
            padding-left: 0;
        }

        .color-radio input[type="radio"] {
            display: none;
        }

        .color-radio input[type="radio"] + .cycle {
            display: inline-block;
            height: 25px;
            width: 25px;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }

        .color-radio input[type="radio"]:checked + .cycle {
            border: 2px solid black;
        }
    </style>
{% endblock css %}

{% block content %}
    <a class="btn btn-primary project" data-toggle="modal" data-target="#myModal">
        <i class="fa fa-plus-circle" aria-hidden="true"></i> 创建项目
    </a>


    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">新建项目</h4>
            </div>
            <div class="modal-body">
            
                <form id="regForm">
                    {% csrf_token %}
                    {% for field  in objs %}
                        <div class="form-group">
                            <label for="{{ field.id_for_label}}">{{field.label}}</label>
                            {{field}}
                            <span class="error-msg"></span>    
                        </div>
                    {% endfor %}
                
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关 闭</button>
                <button id="btnSubmit" type="button" class="btn btn-primary">提 交</button>
            </div>
            </div>
        </div>
    </div>

    <!-- Panel -->
    <div class="panel panel-primary">
        <div class="panel-heading"><h3 class="panel-title">标星项目</h3></div>
        <div class="panel-body">
            {% for row in projects.star %}
                <div class="item">
                    <a href="{% url 'web:dashboard' project_id=row.value.id %}" class="title"
                           style="background-color: {{ row.value.get_color_display }};">{{ row.value.name}}</a>
                    <div class="info">
                        <div>
                            <a href="{% url 'web:project_unstar' project_type=row.type project_id=row.value.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color: #f0ad4e;"></i>
                            </a>
                            <span>{{ row.value.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ row.value.join_count }}</span>
                        </div>
                    </div>
                </div>


            {% endfor %}
        </div>
    </div>

    <div class="panel panel-success">
        <div class="panel-heading"><h3 class="panel-title">我的项目</h3></div>
        <div class="panel-body">
            {% for row in projects.my %}
                <div class="item">
                    <a href="{% url 'web:dashboard' project_id=row.id %}" class="title"
                           style="background-color: {{ row.get_color_display }};">{{ row.name }}</a>
                        <div class="info">
                            <div>
                                <a href="{% url 'web:project_star' project_type='my' project_id=row.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5;"></i>
                                </a>
                                <span>{{ row.creator.username }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ row.join_count }}</span>
                            </div>
                        </div>
                    </div>
            {% endfor %}
        </div>
    </div>

    <div class="panel panel-info">
        <div class="panel-heading"><h3 class="panel-title">参与项目</h3></div>
        <div class="panel-body">
            {% for row in projects.join %}
                <div class="item">
                    <a href="{% url 'web:dashboard' project_id=row.id %}" class="title"
                           style="background-color: {{ row.get_color_display }};">{{ row.name }}</a>
                        <div class="info">
                            <div>
                                <a href="{% url 'web:project_star' project_type='join' project_id=row.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5;"></i>
                                </a>
                                <span>{{ row.creator.username }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ row.join_count }}</span>
                            </div>
                        </div>
                    </div>
            {% endfor %}
        </div>
    </div>


{% endblock content %}

{% block js %}
<script>
    $(function(){
            bindClickBtnSubmit();
        })
    function bindClickBtnSubmit(){
        $('#btnSubmit').click(function(){
            $('.error-msg').empty();
            console.log('hi');
            $.ajax({
                url:"{% url 'web:project_list'%}", //to any url
                type:'POST', //'POST', page?val=xxx&?val2=bbb
                dataType:'JSON',
                data: $('#regForm').serialize(),
                success:function(ret){
                    console.log(ret);
                    if (ret.status){
                        //$("#id_randCode").next().text(res.error);
                       location.href = location.href;

                    }else{
                        console.log(ret.msg);
                        $.each(ret.msg,function(key,value){
                            $("#id_"+key).next().text(value[0]);
                        })
                    }
                }
            })
        })
    }
</script>
{% endblock js %}